<?php
// +-------------------------------------------------------------------
// |
// +-------------------------------------------------------------------
// | Copyright (c) 2009-2016 All rights reserved.
// +-------------------------------------------------------------------
namespace Service\Api\V1;

class UserInforList
{
    public $login = true; //是否需要登录才能访问该接口
    public $title = "用户帖子列表ok";
    public $group = '帖子';
    public $desc = "";

    public $input = [
        'page_num' => 'int;label=分页;comment=默认为1',
        'page_size' => 'int;label=分页条数;comment=默认为5',
    ];

    public $output = [
        'page_num' => 'label=当前页码;',
        'page_size' => 'label=每页条数;',
        'page_count' => 'label=总条数;',
        'page_total' => 'label=总页数;',
        'list' => [
            [
                'id' => 'label=id;',
                'title' => 'label=标题;',
                'logo' => 'label=logo;',
                'describe' => 'label=描述;',
                'create_time' => 'label=创建时间;',
                'state' => 'label=状态： 1上架 0下架;',
            ]
        ]
    ];

    public function run($param, $uid)
    {
        $page_num = $param['page_num'] ?: 1;
        $page_size = $param['page_size'] ?: 10;

        $list = M('user_infor')
            ->where([
                'uid' => $uid,
            ])
            ->order('id desc')->page($page_num, $page_size)
            ->select();
        foreach($list as &$item){
            $logo_arr = explode(',', $item['img']);
            $item['logo'] = $logo_arr[0];
        }
        $count = M('user_infor')
            ->where([
                'uid' => $uid,
            ])->count();
        return [
            'list'=> $list,
            'page_count' => $count,
            'page_total' => ceil($count / $page_size)
        ];
    }
}
